//
//  LoginViewController.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/7/23.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "LoginViewController.h"
#import <JFBase/UITextField+LimitLength.h>
#import "SignUpViewController.h"
#import <JFKit/FZAlertController.h>
#import "AppDelegate.h"
#import "HYApp-Swift.h"


@interface LoginViewController ()

@property (weak, nonatomic) IBOutlet UITextField *account;
@property (weak, nonatomic) IBOutlet UITextField *password;
@property (strong, nonatomic) UIButton *secret;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.account setLeftImageName:@"account_icon"];
    [self.password setLeftImageName:@"password_icon"];
    
    [self.password addSecretButton];
}

- (IBAction)pushSignUpVc:(id)sender {
    
    FZAlertController *vc = [FZAlertController alertControllerWithTitleImage:[UIImage imageNamed:@"Captcha_ico_b"] title:@"GA code" customView:nil message:nil];
    vc.showCloseBtn = YES;
    [vc addTextFieldWithConfigurationHandler:^(UITextField *textField) {
          
    }];
    FZAlertAction *action = [FZAlertAction actionWithTitle:JFMainLocalizedString(@"confirm") style:UIAlertActionStyleDefault handler:^(FZAlertAction *action) {
                        }];
    [vc addAction:action];
    [self presentViewController:vc animated:YES completion:nil];
}

- (IBAction)googleLogin:(UIButton *)sender {
    A0WebAuth * webAuth = [[A0WebAuth alloc] init];
    [webAuth setScope:@"openid profile email"];
    [webAuth start:^(NSError * error, A0Credentials * data) {
        if (!error) {

            [HYNetHelper auth0auth:data.accessToken appId:[HYNetHelper appid] tfaToken:@"" verifyType:@"2" callBack:^(JFResultVo *resultVo) {
                if (resultVo.errorNo == 0) {
                    [HYNetHelper setAuthToken:resultVo.results[@"token"]];
                    [[NSNotificationCenter defaultCenter]postNotificationName:@"changeRoot" object:nil];
                }else{
                    
                    
                }
            }];
        }
    }];
}
@end
